package brushexercises.day60;

/**
 * 125. 验证回文串
 */
public class NO_125_ValidPalindrome {


    public static void main(String[] args) {
        NO_125_ValidPalindrome validPalindrome = new NO_125_ValidPalindrome();
        //String s = "A man, a plan, a canal: Panama";
        String s = "abcba1";
        System.out.println(validPalindrome.isPalindrome(s));
    }

    public boolean isPalindrome(String s) {
        int left = 0;
        int right = s.length()-1;
        while (left < right){
            char cLeft = s.charAt(left);
            char cRight = s.charAt(right);
            if(!Character.isLetterOrDigit(cLeft)){
                left++;
                continue;
            }
            if(!Character.isLetterOrDigit(cRight)) {
                right--;
                continue;
            }
            if(Character.toLowerCase(cLeft) != Character.toLowerCase(cRight)){
                return false;
            }
            left++;
            right--;
        }
        return true;
    }
}
